<?php
$currentDate = date_parse(date("Y-m-d"));

if (isset($_POST['releaseShift'])) {
    releaseShift($_SESSION['userName'], $_SESSION['userPassHash'], $_POST['releaseShift']);
}
?>
<h3>Welcome <?php
    echo($_SESSION['userName']);
    ?> your upcoming schedule is: </h3>
<?php
$err = new ErrorCode();
$shiftsOffered = viewMySchedule(
        $_SESSION['userName'], $_SESSION['userPassHash']);
if ($shiftsOffered['0'] == $err::successRead) {
    ?>
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>Role Name</th>
                <th>Date</th>
                <th>Start Time</th>
                <th>End Time</th>
                <th>Release Shift</th>
            </tr>
        </thead>
        <tbody>
            <?php
            for ($i = 1; $i < count($shiftsOffered); $i++) {
                if (date_parse($shiftsOffered[$i]["date"]) > $currentDate) {
                    ?><tr>
                        <td><?php echo($shiftsOffered[$i]["roleName"]); ?></td>
                        <td><?php echo($shiftsOffered[$i]["date"]); ?></td>
                        <td><?php echo($shiftsOffered[$i]["startTime"]); ?></td>
                        <td><?php echo($shiftsOffered[$i]["endTime"]); ?></td>
                        <td><?php
                            if ($shiftsOffered[$i]["shiftStatus"] != "Vacant") {
                                ?><form action="" method="post">
                                <input type="hidden" name="releaseShift" value='<?php echo(json_encode(array('RoleID' => $shiftsOffered[$i]['roleID'], 'dateID' => $shiftsOffered[$i]['dateID']))); ?>' /><input class="btn" type="submit" value="Release Shift" /></form>
                                <?php
                            } else {
                                ?>Vacant<?php
                                }
                                ?></td>
                    </tr>
                    <?php
                }
            }
            ?>
    </table>
    <?php
} else {
    //can display the error message here if needed 
    ?>No shifts were found.<?php
}
?>